import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

class MyThreadPool{
    private BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
    public MyThreadPool(int n){
        for (int i = 0; i < n; i++) {
            Thread t1 = new Thread(() -> {
                try {
                    while(true){
                        Runnable task = queue.take();
                        task.run();
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            });
            t1.setDaemon(true);
            t1.start();
        }
    }
    public void submit(Runnable task) throws InterruptedException {
         queue.put(task);
    }
}



public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool myThreadPool = new MyThreadPool(4);
        for (int i = 0;i < 1000;i++){
            int id = i;
            myThreadPool.submit(() -> {
                Thread t = Thread.currentThread();
                System.out.println("hello" + t.getName() + " " + id);
            });
        }
        Thread.sleep(1000);
    }
}
